package mylab.starters.mq.impl.ons;

import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.google.common.base.Joiner;
import mylab.starters.mq.config.MqPropperties;

import java.util.Properties;


public class OnsUtil {


    public static Properties tcpProperties(MqPropperties.OnsTcpProperties tcpProperties, String groupId) {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.AccessKey, tcpProperties.getAccessKey());
        properties.put(PropertyKeyConst.SecretKey, tcpProperties.getSecretKey());
        properties.put(PropertyKeyConst.NAMESRV_ADDR, tcpProperties.getBrokers());
        properties.put(PropertyKeyConst.GROUP_ID, groupId);

        return properties;
    }

    public static String tagsFromArray(String... tags) {
        String subExpression = "*";
        if (tags != null && tags.length > 0) {
            subExpression = Joiner.on("||").skipNulls().join(tags);
        }
        return subExpression;
    }
}
